package servlet;

import javabean.Point;
import service.PointService;
import service.PointServiceImpl;
import servlet.BaseServlet.BaseServlet;
import utils.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/pointservlet")
public class PointServlet extends BaseServlet {
    PointService pointService =new PointServiceImpl();
    public void addPoint(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Point point = WebUtils.copyParamToBean(req.getParameterMap(),new Point());
        pointService.savePoint(point);
        resp.sendRedirect(req.getContextPath()+"/pointservlet?action=queryPointList");
    }
    public void queryPointList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("pointlist",pointService.queryPointList());
        req.getRequestDispatcher("/pc/web_integral_manager.jsp").forward(req,resp);
    }
    public void deletePointById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        pointService.deletePointById(Integer.parseInt(id));
        resp.sendRedirect(req.getContextPath()+"/pointservlet?action=queryPointList");
    }
}
